package god530.com.simpleapp_slide.account.tabs.write;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import god530.com.simpleapp_slide.R;
import god530.com.simpleapp_slide.account.title.TitleBarUtils;
import god530.com.simpleapp_slide.account.tabs.write.fragment.OutcomFragment;
import god530.com.simpleapp_slide.account.tabs.write.interf.OnFragmentInteractionListener;

public class WriteActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener
    , OnFragmentInteractionListener, View.OnClickListener
{

    private ViewPager write_viewpager;
    private List<Fragment> listFragment;

    public  static final void lauch(Context ctx) {
        Intent intent = new Intent(ctx, WriteActivity.class);
        ctx.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write);

        initData();
        initView();
        initViewPager();
    }

    private void initData() {

    }

    private void initView() {
        TitleBarUtils titleBarUtils = new TitleBarUtils(findViewById(R.id.write_titlebar));
        titleBarUtils.setLeftViewClickListener(this);
        titleBarUtils.setTitleView("记账");

        View write_tabs_downbar = findViewById(R.id.write_tabs_downbar);

    }

    /** 初始化ViewPager */
    private void initViewPager() {
        listFragment = new ArrayList<>();
        listFragment.add(OutcomFragment.newInstance("", ""));
        listFragment.add(OutcomFragment.newInstance("", ""));
        listFragment.add(OutcomFragment.newInstance("", ""));
        listFragment.add(OutcomFragment.newInstance("", ""));

        // ViewPager
        write_viewpager = (ViewPager) findViewById(R.id.write_viewpager);
        write_viewpager.setAdapter(new MyPageAdapter(getSupportFragmentManager()));
        write_viewpager.addOnPageChangeListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        write_viewpager.removeOnPageChangeListener(this);
    }

    //////////////////////////////////////////////////////////////////////

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    ////////////////////////////////////////////////////////////////////

    @Override
    public void onFragmentInteraction(Uri uri) {

    }

    ////////////////////////////////////////////////////////////////////

    @Override
    public void onClick(View v) {

    }

    //////////////////////////////////////////////////////////////////////

    class MyPageAdapter extends FragmentPagerAdapter {

        public MyPageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return listFragment.get(position);
        }

        @Override
        public int getCount() {
            return listFragment.size();
        }
    }

    ////////////////////////////////////////////////////////////////////

}
